package com.orchid.community.models.controller;

import cn.hutool.core.util.StrUtil;
import com.orchid.community.common.utils.CodeEnum;
import com.orchid.community.common.utils.MsgResponse;
import com.orchid.community.common.utils.ResultUtils;
import com.orchid.community.models.DTO.MissionDto;
import com.orchid.community.models.DTO.PeopleDTO;
import com.orchid.community.models.DTO.UserInfoDTO;
import com.orchid.community.models.service.AppletUserService;
import com.orchid.community.models.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/applet/user")
public class AppletUserController {

    @Autowired
    private AppletUserService appletUserService;

    @Autowired
    private UserService userService;


    @PostMapping("/login")
    public MsgResponse login(@RequestBody Map<String, Object> map){
        System.out.println(map);

        return appletUserService.login(map);
    }

    @PostMapping("/getMissionList")
    public MsgResponse getMissionList(@RequestBody MissionDto missionDto){
        return appletUserService.getMissionList(missionDto);
    }

    @PostMapping("/updateUserInfo")
    public MsgResponse updateUserInfo(@RequestBody UserInfoDTO users)
    {
        if (users == null || users.getUserId() == null){
            return ResultUtils.fail(CodeEnum.PARAM_ERROR);
        }
        return userService.updateUserInfo(users);
    }

    @PostMapping("/getUserInfo")
    public MsgResponse getUserInfo(@RequestBody UserInfoDTO users)
    {
        if (users == null || users.getUserId() == null){
            return ResultUtils.fail(CodeEnum.PARAM_ERROR);
        }
        return userService.getUserInfo(users);

    }

    @PostMapping("/updateBody")
    public MsgResponse updateBody(@RequestBody PeopleDTO people)
    {
        return userService.updateBody(people);
    }

    @PostMapping("/getPeopleInfo")
    public MsgResponse getPeopleInfo(@RequestBody PeopleDTO people)
    {
        return userService.getPeopleInfo(people);
    }

    @PostMapping("/apply")
    public MsgResponse apply(@RequestBody Map<String, Object> map){
        if(map.get("userId") == null || map.get("missionId") == null ){
            return ResultUtils.fail("请检查参数");
        }
        return userService.apply(map);
    }

    @PostMapping("/getApplyInfo")
    public MsgResponse getApplyInfo(@RequestBody Map<String, Object> map){
        if(map.get("userId") == null || map.get("missionId") == null ){
            return ResultUtils.fail("请检查参数");
        }
        return userService.getApplyInfo(map);
    }


}
